import { UIHelper } from "../game/util/UIHelper";
import ComponentBase from "./ComponentBase";
import { Logger } from "./Logger";

const { ccclass, property,menu } = cc._decorator;


@ccclass('WebViewPrefab')
@menu("view/WebViewPrefab")
export class WebViewPrefab extends ComponentBase {

    public static instance: WebViewPrefab;

    private webView: cc.WebView
    private url: string = "http://119.23.247.29:13000/juyou"


    onLoad() {
        super.onLoad();
        WebViewPrefab.instance = this;
        this.webView = this.getChild(this.node, "webView", cc.WebView);
        let btnBack: cc.Node = this.getChild(this.node, "buttomNode/btnBack")
        UIHelper.onAddEvent(btnBack, () => {
            Logger.log("btnBack==")
            this.hide();
        })
        let btnBrower: cc.Node = this.getChild(this.node, "buttomNode/btnBrower")
        UIHelper.onAddEvent(btnBrower, () => {
            cc.sys.openURL(this.url)
        })
        // Logger.log("WebViewPrefab onLoad==")
    }

    start() {
        // this.hide()
    }

    public show(url: string = "https://cocos.com") {
        this.url = url;
        this.webView.url = url
        WebViewPrefab.instance.node.active = true;
    }


    public hide() {
        WebViewPrefab.instance.node.active = false;
    }

    onDestroy() {
    }

}

